﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Designer.Views
{
    public delegate void OperationDoEventHandler(OperationBase command);
    public delegate void OperationUndoEventHandler(OperationBase command);

    public abstract class OperationBase
    {
        /// <summary>
        /// 执行
        /// </summary>
        public void Do()
        {
            OnDo();
            if (DoEvent != null)
            {
                DoEvent(this);
            }
        }

        /// <summary>
        /// 撤销
        /// </summary>
        public void Undo()
        {
            OnUndo();
            if (UndoEvent != null)
            {
                UndoEvent(this);
            }
        }

        /// <summary>
        /// 执行
        /// </summary>
        protected abstract void OnDo();

        /// <summary>
        /// 撤销
        /// </summary>
        protected abstract void OnUndo();

        public event OperationDoEventHandler DoEvent;
        public event OperationUndoEventHandler UndoEvent; 
    }
}
